<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>DNS查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    <style media="screen">
        .x-container{
            padding-top:10px;
        }
    </style>
</head>
<body>
<div class="layui-container x-container">
    <form class="layui-form" action="" onsubmit="return false;">
        <div class="layui-form-item">
            <label class="layui-form-label">输入域名</label>
            <div class="layui-input-block">
                <input type="text" name="domain" lay-verify="domain" autocomplete="off" value="i.fe80.cn" placeholder="请输入域名" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
		    <label class="layui-form-label">网站名称</label>
		    <div class="layui-input-block">
		        <input type="text" name="name" lay-verify="name" autocomplete="off" value="" placeholder="请输入网站名称" class="layui-input">
		    </div>
		</div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>

                <a class="layui-btn" href="./index.html">IPv6查询</a>
            </div>
        </div>
		<div class="layui-form-item">
		    <label class="layui-form-label">域名</label>
		    <div class="layui-input-block">
		        <input type="text" name="domain1" readonly="readonly" placeholder="域名" autocomplete="off" class="layui-input">
		    </div>
		</div>
        <div class="layui-form-item">
            <label class="layui-form-label">IPv4</label>
            <div class="layui-input-block">
                <input type="text" name="ipv4" readonly="readonly" placeholder="IPv4" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">IPv6</label>
            <div class="layui-input-block">
                <input type="text" name="ipv6" readonly="readonly" placeholder="IPv6" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">CNAME</label>
            <div class="layui-input-block">
                <input type="text" name="cname" readonly="readonly" placeholder="cname" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="https://www.layuicdn.com/layui/layui.js"></script>
<script type="text/javascript" src="./assets/jquery.min.js"></script>
<script type="text/javascript" src="./assets/ipv6solution.js"></script>
<script>
layui.use(['form'],function(){
    var form=layui.form,$=layui.jquery,layer=layui.layer;
    form.on("submit(demo1)",function(data){
		var domain = data.field.domain;
		console.log('0-00'+domain);
		var s = domain.split('//');
		if(s.length > 1){
			console.log(s);
			domain = s[1];
		}
		console.log('000'+domain);
		var s1 = domain.split('/');
		if( s1 && s1.length > 0){
			console.log(s1);
			domain = s1[0];
		}
        var mepu =  window.location.protocol + "//i.fe80.cn/tools/domain/dns?host=";
		$("input[name='ipv4']").val('');
		$("input[name='ipv6']").val('');
		$("input[name='cname']").val('');
		$("input[name='domain1']").val(domain);
		var xname = data.field.name;
		var datax = {domain:domain};
		if(xname){
			datax.name = xname;
		}
        $.post( mepu + domain, datax, function(res){
			var a = JSON.parse(res.data.dns_a);
			if(a && a.length > 0){
				$("input[name='ipv4']").val(a[0].ip);
			}
			var aaaa = JSON.parse(res.data.dns_aaaa);
			if(aaaa && aaaa.length > 0){
				$("input[name='ipv6']").val(aaaa[0].ipv6);
			}
			var cname = JSON.parse(res.data.dns_cname);
			if(cname && cname.length > 0){
				$("input[name='cname']").val(cname[0].target);
			}
        },'json').error(function(e){
			console.log(e);
			layer.msg('服务器错误',{icon:2});
		});
        return false;
    });
});
</script>
</body>
</html>
